<?php

class Admin_Admin_Controller extends Base_Controller {

	public function action_index()
	{
		return View::make('admin.index');
	}

	public function action_admininfo()
	{

		$admininfo = DB::table('admin') -> paginate(15);
		foreach($admininfo->results as $key => $val){
            $admininfo->results[$key]['creattime'] = date('Y-m-d H:i:s',$val['creattime']);
        }

        return json_encode(array('code'=>0,'msg'=>'','count'=> $admininfo->total,'data'=>$admininfo->results));

	}

	public function action_adminlist()
	{

		return View::make('admin.adminlist');
	}

	public function action_showadmin()
	{

		return View::make('admin.showadmin');
	}

	public function action_changeadmin()
	{
		$id = Input::get('id');
		$admininfo = DB::table('admin')->where('id','=',$id)->first();
		return View::make('admin.changeadmin',array('admininfo'=>$admininfo));
	}

	public function action_dochangeadmin()
	{
		$username = Input::get('username');
		$password = Input::get('password');
		$id = Input::get('id');
		$chang = DB::table('admin')->where('id','=',$id)->update(array('username'=>$username,'password'=>$password));
		if($chang){
			return json_encode(array('code'=>200,'msg'=>'修改成功'));
		}else{
			return json_encode(array('code'=>400,'msg'=>'修改失败'));
		}
	}















}